package com.github.distribute.test;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import org.apache.zookeeper.ZooKeeper;

import com.github.distribute.lock.zookeeper.ZookeeperDistributeLock;

public class Outputter2 {
	ZooKeeper zooKeeper = null;
	ZookeeperDistributeLock lock = null;
	
	
	public Outputter2(ZooKeeper zooKeeper,String root) throws IOException {
		this.zooKeeper=zooKeeper;
		//zooKeeper=new ZooKeeper("192.168.0.159:2181", 60000, null);
		lock=new ZookeeperDistributeLock(zooKeeper, root, "lock-");
	}
	
	 public void output(String name) throws Exception {  
	        try {  
	        	lock.lock();
	        	
	        	//lock.lock(500, TimeUnit.MILLISECONDS);
	            for(int i = 0; i < name.length(); i++) {  
	                System.out.print(name.charAt(i));  
	            }  
	            System.out.println();
	        } finally {
	        	lock.unLock();
	        }  
	 }  
}
